package com.liucxu.zimuzu.Presenter.Impl;

import com.liucxu.zimuzu.Base.ResponseSubscriber;
import com.liucxu.zimuzu.Model.Bean.HotBean;
import com.liucxu.zimuzu.Model.IHotModel;
import com.liucxu.zimuzu.Model.Impl.HotImpl;
import com.liucxu.zimuzu.Presenter.IHotPresenter;
import com.liucxu.zimuzu.Utils.TransformUtils;
import com.liucxu.zimuzu.View.IView.IHotView;

/**
 * 热门presenter的实现类
 * Created by liukanshan on 2016/12/8.
 */

public class HotPresenterImpl implements IHotPresenter {

    private IHotModel iHotModelImpl;
    private IHotView iHotView;

    public HotPresenterImpl(IHotView view) {
        iHotModelImpl = new HotImpl();
        iHotView = view;
    }

    @Override
    public void getTopHot(String channel) {
        iHotView.showLoading();
        iHotModelImpl.getTopHot(channel).compose(TransformUtils.<HotBean>defaultSchedulers()).subscribe(new ResponseSubscriber<HotBean>() {
            @Override
            public void onSuccess(HotBean bean) {
                iHotView.hideLoading();
                iHotView.setHots(bean);
            }

            @Override
            public void onFailure(Throwable error) {
                iHotView.hideLoading();
                iHotView.showError(error.getMessage());
            }
        });
    }
}
